
#include <linux/init.h>   
#include <linux/module.h> 
#include <linux/platform_device.h> //平台设备所需要的头文件


#define CCM_CCGR1_BASE              (0X020C406C)
#define SW_MUX_CTL_PAD_USAT1_RTS_B  (0X020E0000)
#define SW_PAD_CTL_PAD_UART1_RTS_B  (0x020e031C)
#define GPIO1_DR_BASE               (0x0209C000) 
#define GPIO1_GDIR_BASE             (0x0209C004)
#define REG_LENGTH                   4
// 设备释放时执行的代码
void beep_release(struct device *dev){
    printk("beep_release \n");

}

struct resource beep_res[] = {
    [0] = {                 //时钟
        .start = CCM_CCGR1_BASE,
        .end = (CCM_CCGR1_BASE+REG_LENGTH-1),
        .flags = IORESOURCE_MEM,
    },
    [1] ={                  //mux
        .start = SW_MUX_CTL_PAD_USAT1_RTS_B,
        .end = (SW_MUX_CTL_PAD_USAT1_RTS_B+REG_LENGTH-1),
        .flags = IORESOURCE_MEM,
    },
    [2] ={                  //pad
         .start = SW_PAD_CTL_PAD_UART1_RTS_B,
        .end = (SW_PAD_CTL_PAD_UART1_RTS_B+REG_LENGTH-1),
        .flags = IORESOURCE_MEM,
    },
    [3] = {                 //dr
        .start = GPIO1_DR_BASE,
        .end = (GPIO1_DR_BASE+REG_LENGTH-1),
        .flags = IORESOURCE_MEM,
    },
    [4] = {                 //gdir
        .start = GPIO1_GDIR_BASE,
        .end = (GPIO1_GDIR_BASE+REG_LENGTH-1),
        .flags = IORESOURCE_MEM,
    }
};

//platform 设备结构体
static struct platform_device BeepDevice = {
    .name = "imx6ull-beep",
    .id = -1,
    .dev = {
        .release = &beep_release,    //void beep_release(struct device *dev)
    },
    .num_resources = ARRAY_SIZE(beep_res),
    .resource = beep_res,
};


//设备的初始化
static int __init beepdevice_init(void)
{
    return platform_device_register(&BeepDevice); //static struct platform_device BeepDevice
}


//设备的卸载注销
static void __exit beepdevice_exit(void)
{
    platform_device_unregister(&BeepDevice);
}

module_init(beepdevice_init);
module_exit(beepdevice_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("ZzlYanG");
